﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using ATSIDAL;
using ATSModel;

namespace ATSDAL
{
    public class ElecBatchReport : BaseRepository_DataSet, IElecBatchReport
    {
        private const string PARM_TESTITEM_SN = "@ProductSN";
        private const string PARM_TESTITEM_TypeID = "@ProductTypeID";
        private const string PARM_TESTITEM_MO = "@MOID";
        private const string PARM_TESTITEM_TestType = "@TestStep";
        private const string PARM_TESTITEM_DataType = "@DataType";
        private const string PARM_TESTITEM_Date = "@TestDate";

        private const string PARM_TESTITEM_sDt = "@SDate";
        private const string PARM_TESTITEM_eDt = "@EDate";

        private const string PARM_TESTITEM_USERID = "@UserID"; 

        // 根据条码获取数据
        public DataSet ElecData_ByProSN(string TableName, string ProSN)
        {
            SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_SN);
            testItemParms[0].Value = ProSN;

            return ExcuteDataset("Elec_Detail_BYProSNUP", TableName, testItemParms);
        }

        // 根据产品型号获取数据
        public DataSet ElecData_ByProTypeID(string TableName, string ProTypeID)
        {
            SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_TypeID);
            testItemParms[0].Value = ProTypeID;

            return ExcuteDataset("Elec_Detail_BYProTypeIDUP", TableName, testItemParms);
        }

         // 根据MO号获取数据
        public DataSet ElecData_ByMO(string TableName, string MOID)
        {
            SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_MO);
            testItemParms[0].Value = MOID;

            return ExcuteDataset("Elec_Detail_BYMOIDUP", TableName, testItemParms);
        }

        public DataSet ELData_ByMOandDte(string TableName, string MOID, string sDt, string eDt)
        {
            SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_MO, PARM_TESTITEM_sDt, PARM_TESTITEM_eDt);
            testItemParms[0].Value = MOID;
            testItemParms[1].Value = sDt;
            testItemParms[2].Value = eDt;
            return ExcuteDataset("Elec_Detail_BYMOIDAndDateUP", TableName, testItemParms);
        }

        /// <summary>
        /// 根据用户与时间复合检索
        /// </summary>
        /// <param name="UserID">测试人员</param> 
        /// <param name="sDt">开始时间</param>
        /// <param name="eDt">结束时间</param>
        /// <returns></returns>
        public DataSet ELData_ByUserIDandDte(string TableName, string UserID, string sDt, string eDt)
        {
            SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_USERID, PARM_TESTITEM_sDt, PARM_TESTITEM_eDt);
            testItemParms[0].Value = UserID;
            testItemParms[1].Value = sDt;
            testItemParms[2].Value = eDt;
            return ExcuteDataset("Elec_Detail_BYUserIDAndDateUP", TableName, testItemParms);
        }


        /// <summary>
        /// 根据时间检索
        /// </summary> 
        /// <param name="sDt">开始时间</param>
        /// <param name="eDt">结束时间</param>
        /// <returns></returns>
        public DataSet ELData_ByDte(string TableName, string sDt, string eDt)
        {
            SqlParameter[] testParms = GetDTParameters();
            //Bind the parameter
            testParms[0].Value = sDt;
            testParms[1].Value = eDt;
            return ExcuteDataset("Elec_Detail_BYDateUP", TableName, testParms);
        } 


        // 根据MO号获取数据
        public DataSet ElecData_ByMOS(string TableName, string MOID)
        {
            SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_MO);
            testItemParms[0].Value = MOID;

            return ExcuteDataset("Elec_BYMOID_DetailUP", TableName, testItemParms);
        }
         
        // 根据条码获取数据
        public DataSet ElecData_ByProSNS(string TableName, string ProSN)
        {
            SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_SN);
            testItemParms[0].Value = ProSN;

            return ExcuteDataset("Elec_BYProSN_DetailUP", TableName, testItemParms);
        }

        // 根据产品型号获取数据
        public DataSet ElecData_ByProTypeIDS(string TableName, string ProTypeID)
        {
            SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_TypeID);
            testItemParms[0].Value = ProTypeID;

            return ExcuteDataset("Elec_BYProTypeID_DetailUP", TableName, testItemParms);
        }
        public DataSet ELData_ByMOandDteS(string TableName, string MOID, string sDt, string eDt)
        {
            SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_MO, PARM_TESTITEM_sDt, PARM_TESTITEM_eDt);
            testItemParms[0].Value = MOID;
            testItemParms[1].Value = sDt;
            testItemParms[2].Value = eDt;
            return ExcuteDataset("Elec_BYMOIDAndDate_DetailUP", TableName, testItemParms);
        }


        /// <summary>
        /// 根据用户与时间复合检索
        /// </summary>
        /// <param name="UserID">测试人员</param> 
        /// <param name="sDt">开始时间</param>
        /// <param name="eDt">结束时间</param>
        /// <returns></returns>
        public DataSet ELData_ByUserAndDteS(string TableName, string UserID, string sDt, string eDt)
        {
            SqlParameter[] testItemParms = GetSNTParameters(PARM_TESTITEM_USERID, PARM_TESTITEM_sDt, PARM_TESTITEM_eDt);
            testItemParms[0].Value = UserID;
            testItemParms[1].Value = sDt;
            testItemParms[2].Value = eDt;
            return ExcuteDataset("Elec_BYUserAndDate_DetailUP", TableName, testItemParms);
        }

        /// <summary>
        /// 根据时间检索
        /// </summary> 
        /// <param name="sDt">开始时间</param>
        /// <param name="eDt">结束时间</param>
        /// <returns></returns>
        public DataSet ELData_ByDtes(string TableName, string sDt, string eDt)
        {
            SqlParameter[] testParms = GetDTParameters();
            //Bind the parameter
            testParms[0].Value = sDt;
            testParms[1].Value = eDt;
            return ExcuteDataset("Elec_BYDate_DetailUP", TableName, testParms);
        } 


        #region 参数部分
        private static SqlParameter[] GetSNTParameters(string Par)
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(Par, SqlDbType.Text),           
                };
            return parms;
        }


         private static SqlParameter[] GetSNTParameters(string Par1, string Par2, string Par3)
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(Par1, SqlDbType.Text), 
                    new SqlParameter(Par2, SqlDbType.DateTime, 8),
                    new SqlParameter(Par3, SqlDbType.DateTime, 8) 
                };
            return parms;
        }
     

        private static SqlParameter[] GetSNTParameters(string Par1, string Par2, string Par3, string Par4)
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(Par1, SqlDbType.Text), 
                    new SqlParameter(Par2, SqlDbType.Text),
                    new SqlParameter(Par3, SqlDbType.Text),
                    new SqlParameter(Par4, SqlDbType.DateTime, 8),
                };
            return parms;
        }

        public SqlParameter[] GetDTParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
                    new SqlParameter(PARM_TESTITEM_sDt, SqlDbType.DateTime,8),
                    new SqlParameter(PARM_TESTITEM_eDt, SqlDbType.DateTime,8),
                };
            return parms;
        }
        #endregion


        #region 重写基类部分
        //-------------------------------------重写超类基础操作---------------------------------------------------------

        #endregion
    }
}
